<?php
include_once("_common.php");
include_once("$mw_cash[path]/cybercash.lib.php");
include_once("$g4[path]/head.sub.php");

if (!$is_member)
    alert("로그인 후 이용해주세요.");

$cash_contents = get_session("cash_contents");
if ($cash_contents) {
    $tmp = explode("@", get_session("cash_contents"));
    $bo_table = $tmp[0];
    $wr_id = $tmp[1];
    $no = $tmp[2];
}

$board = sql_fetch("select * from $g4[board_table] where bo_table = '$bo_table'");
if (!$board)
    alert("게시판 [$bo_table] 은 존재하지 않습니다.");

$write_table = "$g4[write_prefix]$bo_table";
$write = sql_fetch("select * from $write_table where wr_id = '$wr_id'");
if (!$write)
    alert("컨텐츠가 존재하지 않습니다.");

$board_skin_path = "$g4[path]/skin/board/$board[bo_skin]";

include_once("$board_skin_path/mw.lib/mw.skin.basic.lib.php");

if (!$write[wr_contents_price])
    alert("무료 컨텐츠는 결제할 필요가 없습니다.");

mw_buy_contents($member[mb_id], $bo_table, $wr_id, $cl_domain);

set_session("cash_contents", '');
set_session("cash_membership", '');
set_session("download_membership", '');

/*if ($mw_basic[cf_download_popup]) {
    $url = "$g4[path]/skin/board/$board[bo_skin]/mw.proc/download.popup.skin.php?bo_table=$$bo_table&wr_id=$wr_id&no=$no";
}
else {
    $url = "$g4[bbs_path]/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no";
}*/

if ($mw_basic[cf_contents_shop] == '1') { // 다운로드 결제
    $url = "$g4[bbs_path]/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no";
    ?>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
    <tr>
        <td style="text-align:center;">
            <input type="button" style="cursor:pointer; background-color:#efefef;" value="파일 다운로드" onclick="location.href='<?=$url?>'"/>
        </td>
    </tr>
    </table>
    
<? } ?>

<script type="text/javascript">
$(document).ready(function () {
    opener.location.reload(); 
    <? if ($mw_basic[cf_contents_shop] == '2') { // 내용보기 결제 ?>
    self.close();
    <? } ?>
})
</script>

<?
include_once("$g4[path]/tail.sub.php");
